package com.sunyard.client2.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.sunyard.client.SunEcmClientApi;
import com.sunyard.client2.ConnectionFactory;
import com.sunyard.client2.conf.ConfUtil;

public class Login extends JPanel {
	private JTextField textField;
	private JTextField textField_1;

	/**
	 * Create the panel.
	 */
	public Login() {
		setLayout(null);

		JLabel lblNewLabel = new JLabel("用户：");
		lblNewLabel.setBounds(26, 36, 77, 25);
		add(lblNewLabel);

		textField = new JTextField();
		textField.setBounds(112, 38, 111, 21);
		textField.setText(ConfUtil.getString("userName", "admin"));
		add(textField);
		textField.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("密码：");
		lblNewLabel_1.setBounds(303, 41, 54, 15);
		add(lblNewLabel_1);

		textField_1 = new JTextField();
		textField_1.setBounds(367, 38, 103, 21);
		textField_1.setText(ConfUtil.getString("passWord", "111"));
		add(textField_1);
		textField_1.setColumns(10);

		JButton btnNewButton = new JButton("登录");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					SunEcmClientApi clientApi = ConnectionFactory.getConnection();
					String resultMsg = clientApi.login(textField.getText(), textField_1.getText());
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}
			}
		});
		btnNewButton.setBounds(58, 130, 93, 23);
		add(btnNewButton);

		JButton btnNewButton_1 = new JButton("退出");
		btnNewButton_1.setBounds(278, 130, 93, 23);
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					SunEcmClientApi clientApi = ConnectionFactory.getConnection();
					String resultMsg = clientApi.logout(textField.getText());
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}
			}
		});
		add(btnNewButton_1);

	}
}
